package dongze.com.ckdj.activity;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.databinding.DataBindingUtil;
import android.databinding.Observable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import dongze.com.ckdj.BR;
import dongze.com.ckdj.R;
import dongze.com.ckdj.dagger.DataStore;
import dongze.com.ckdj.dagger.component.DaggerVehicleComponent;
import dongze.com.ckdj.dagger.component.SectionComponent;
import dongze.com.ckdj.dagger.component.UserComponent;
import dongze.com.ckdj.dagger.component.VehicleComponent;
import dongze.com.ckdj.dagger.module.VehicleModule;
import dongze.com.ckdj.data.entity.response.BrandResponse;
import dongze.com.ckdj.data.entity.response.InspectionSectionResponse;
import dongze.com.ckdj.data.entity.response.User;
import dongze.com.ckdj.data.entity.response.VehicleInformationDetail;
import dongze.com.ckdj.databinding.InformationItemSpinnerBinding;
import dongze.com.ckdj.databinding.InformationItemTextBinding;
import dongze.com.ckdj.databinding.VehicleNumberItemBinding;
import dongze.com.ckdj.databinding.model.InformationItemSpinnerModel;
import dongze.com.ckdj.databinding.model.InformationItemTextModel;
import dongze.com.ckdj.databinding.model.VehicleNumberModel;
import dongze.com.ckdj.fragment.CheckInOperationFragment;
import dongze.com.ckdj.fragment.EmptyContentFragment;
import dongze.com.ckdj.fragment.PortInspectionFragment;
import dongze.com.ckdj.fragment.ProcessingFragment;
import dongze.com.ckdj.map.MapUtil;
import dongze.com.ckdj.util.MyLog;
import dongze.com.ckdj.util.Util;
import io.reactivex.observers.DisposableObserver;


/**
 * Created by fanqwz on 2017/7/20.
 */

public class CheckInActivity extends BaseActivity {
    private static final String TAG = CheckInActivity.class.getSimpleName();
    private final int QR_REQUEST = 1024;
    private final int CONF_REQUEST = 1025;
    private final int BACK_PRESSED_MSG = 1026;

    @BindView(R.id.basic_info_container)
    GridLayout mBasicInfoLayout;
    @BindView(R.id.vehicle_number_container)
    ViewGroup mVehicleNumberContainer;
    @BindView(R.id.scanner)
    ImageButton mScanner;

    MapUtil mapUtil;
    @Inject
    User mUser;
    @Inject
    InspectionSectionResponse mInspectionSection;
    @Inject
    BrandResponse mBrand;
    @Inject
    DataStore dataStore;

    protected String mCurrentVehicleNumber;
    VehicleInformationDetail vehicleInformationDetail;

    InformationItemTextModel mTimeModel = new InformationItemTextModel();
    InformationItemTextModel mUserModel = new InformationItemTextModel();
    InformationItemTextModel mSectionModel = new InformationItemTextModel();
    VehicleNumberModel mVehicleNumberModel = new VehicleNumberModel();
    InformationItemTextModel mBrandModel = new InformationItemTextModel();
    android.os.Handler mHandler;
    private DisposableObserver mPendingDisposable;
    String vin ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        MyLog.d(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);

        mapUtil = new MapUtil(getAppCompenent());

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_TIME_TICK);
        registerReceiver(mTimeReceiver, intentFilter);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
            getSupportActionBar().setDisplayShowHomeEnabled(false);
        }

        setContentView(R.layout.activity_check_in);
        ButterKnife.bind(this);
        mScanner.setOnClickListener(mOnClickListener);

        mHandler = new android.os.Handler();

        if (getComponent(SectionComponent.class) == null) {
            initConfiguration();
        } else if (getComponent(SectionComponent.class) != null) {
            getComponent(SectionComponent.class).inject(this);
            initData();
        } else {
            finish();
            return;
        }

        if (savedInstanceState != null) {
             vin = savedInstanceState.getString("vin");

            if (!TextUtils.isEmpty(vin))
                loadDetail(vin);
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("vin", mCurrentVehicleNumber);
    }

    @Override
    protected void onDestroy() {
        MyLog.d(TAG, "onDestroy: ");
        dataStore.set(VehicleInformationDetail.class, null);
        addComponent(VehicleComponent.class, null);
        unregisterReceiver(mTimeReceiver);
        mapUtil.dispose();
        super.onDestroy();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.check_in_operation, menu);
        return super.onCreateOptionsMenu(menu);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
//        if (item.getItemId() == R.id.name_plat) {
//            onNamePalteBtnClick(null);
//        }
         if (item.getItemId() == R.id.mass_loss_record) {
            onMassLossBtnClick(null);
        } else if (item.getItemId() == R.id.random_inspection) {
            onRandomInspectionClick(null);
        }
//         else if (item.getItemId() == R.id.record) {
//            onRecordBtnClick(null);
//        }
//        else if (item.getItemId() == R.id.workload) {
//            onWorkloadBtnClick(null);
//        }
        else {
            return super.onOptionsItemSelected(item);
        }

        return true;
    }

    @Override
    public void onBackPressed() {
//        if (!TextUtils.isEmpty(mCurrentVehicleNumber)) {
//            new AlertDialog.Builder(this)
//                    .setMessage("点检记录没有提交，仍要退出吗？")
//                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            mHandler.sendMessage(mHandler.obtainMessage(BACK_PRESSED_MSG));
//                            mCurrentVehicleNumber = null;
//                            CheckInActivity.this.onBackPressed();
//                        }
//                    })
//                    .setNegativeButton(android.R.string.no, null)
//                    .create()
//                    .show();
//        } else {
        if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
            getSupportFragmentManager().popBackStack();
        } else if (mHandler.hasMessages(BACK_PRESSED_MSG)) {
            super.onBackPressed();
        } else {
            Toast.makeText(this, "再次按下返回键退出当前页面", Toast.LENGTH_SHORT).show();
            mHandler.sendMessageDelayed(mHandler.obtainMessage(BACK_PRESSED_MSG), 1500);
        }
//        }
    }

    private void initConfiguration() {
        Intent intent = new Intent(getApplicationContext(), UserPreferenceActivity.class);
        startActivityForResult(intent, CONF_REQUEST);
    }

    private void initData() {
        if (mUser == null) {
            MyLog.e(TAG, "onCreate: user null, activity finished");
            new AlertDialog.Builder(this)
                    .setMessage("user null")
                    .setCancelable(false)
                    .setNegativeButton("exit", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    })
                    .create()
                    .show();
            return;
        }

        mTimeModel.setKey("当前时间");
        mTimeModel.setValue(Util.getCurrentTime(this));
        addBasicInfoItem(mTimeModel);

        mUserModel.setKey("登陆人员");
        mUserModel.setValue(mUser.getRemark() + "-" + mUser.getUser_name());
        addBasicInfoItem(mUserModel);

        addBasicInfoItem(mSectionModel);
        mSectionModel.setKey("点检环节");
        mSectionModel.setValue(mInspectionSection.getNode_name());

        addVehicleNumber(mVehicleNumberModel);

        mBrandModel.setKey("品牌");
        mBrandModel.setValue(mBrand.getBrand_name());
//        addBrandName(mBrandModel);
        addBasicInfoItem(mBrandModel);

        loadEmptyFragment();
    }


    private void addBrandName(InformationItemTextModel model) {
        if (getResources().getDisplayMetrics().widthPixels > getResources().getDimensionPixelSize(R.dimen.vehicle_number_value_min_width) * 2) {
            InformationItemTextBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.information_item_text, mBasicInfoLayout, false);
            binding.getRoot().setTag(binding);
            binding.setVehicleInformationItemText(model);

            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            int margin = getResources().getDimensionPixelSize(R.dimen.basic_info_item_margin);
            params.setMargins(margin, margin, margin, margin);
            params.addRule(RelativeLayout.CENTER_VERTICAL);
            params.addRule(RelativeLayout.ALIGN_LEFT);
            ((RelativeLayout) mVehicleNumberContainer.getParent()).addView(binding.getRoot(), params);
        } else { // 宽度不够的情况下
            addBasicInfoItem(model);
        }
    }

    private void addVehicleNumber(VehicleNumberModel model) {
        VehicleNumberItemBinding vehicleNumberItemBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.vehicle_number_item, mVehicleNumberContainer, false);
        model.setKey("车架号");
        model.setOnItemClickListener(mOnVehicleNumberClick);
        vehicleNumberItemBinding.setInformationItemAutoCompleteTextModel(model);
        model.addOnPropertyChangedCallback(mOnVehicleNumberChangedListener);
        mVehicleNumberContainer.addView(vehicleNumberItemBinding.getRoot());
    }

    private void addBasicInfoItem(InformationItemTextModel model) {
        InformationItemTextBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.information_item_text, mBasicInfoLayout, false);
        binding.getRoot().setTag(binding);
        binding.setVehicleInformationItemText(model);
        int count = mBasicInfoLayout.getColumnCount();
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(GridLayout.spec(mBasicInfoLayout.getChildCount() / count, 1), GridLayout.spec(mBasicInfoLayout.getChildCount() % count, 1));
        params.width = (getResources().getDisplayMetrics().widthPixels) / count;

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            params = new GridLayout.LayoutParams(GridLayout.spec(mBasicInfoLayout.getChildCount() / count, 1, 0.5f), GridLayout.spec(mBasicInfoLayout.getChildCount() % count, 1, 0.5f));
//        }

        int margin = getResources().getDimensionPixelSize(R.dimen.basic_info_item_margin);
        params.setMargins(margin, margin, margin, margin);
        mBasicInfoLayout.addView(binding.getRoot(), params);
    }

    private void addDropDownInfoItem(InformationItemSpinnerModel model) {
        InformationItemSpinnerBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.information_item_spinner, mBasicInfoLayout, false);
        binding.getRoot().setTag(binding);
        binding.setVehicleInformationItemSpinner(model);
        int count = mBasicInfoLayout.getColumnCount();
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(GridLayout.spec(mBasicInfoLayout.getChildCount() / count, 1), GridLayout.spec(mBasicInfoLayout.getChildCount() % count, 1));
        params.width = (getResources().getDisplayMetrics().widthPixels) / count;

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            params = new GridLayout.LayoutParams(GridLayout.spec(mBasicInfoLayout.getChildCount() / count, 1, 0.5f), GridLayout.spec(mBasicInfoLayout.getChildCount() % count, 1, 0.5f));
//        }

        int margin = getResources().getDimensionPixelSize(R.dimen.basic_info_item_margin);
        params.setMargins(margin, margin, margin, margin);
        mBasicInfoLayout.addView(binding.getRoot(), params);
    }

    private void loadDetail(final String vehicleNumber) {
        if (TextUtils.equals(vehicleNumber, mCurrentVehicleNumber)) {
            mVehicleNumberModel.setValue(null);
            Toast.makeText(this, "车架号重复", Toast.LENGTH_SHORT).show();
            return;
        }

        MyLog.v(TAG, "loadDetail:" + vehicleNumber);

        final Runnable showRunnable = new Runnable() {
            @Override
            public void run() {
                mVehicleNumberModel.setEntries(null);
                mVehicleNumberModel.setValue(null);
                mVehicleNumberModel.setHint(null);
                loadProcessingFragment();
                mapUtil.getVehicleDetail(vehicleNumber, mInspectionSection.getNode_code(), new DisposableObserver<VehicleInformationDetail>() {

                    @Override
                    public void onNext(final VehicleInformationDetail value) {
                        if (getComponent(SectionComponent.class) == null) {
                            MyLog.e(TAG, "load detail but sectionComponent is null");
                            new AlertDialog.Builder(CheckInActivity.this)
                                    .setMessage("load detail but sectionComponent is null")
                                    .create()
                                    .show();
                            return;
                        }

                        if (!TextUtils.isEmpty(value.getRemark()))
                            showRemark(value.getRemark());

                        dataStore.set(VehicleInformationDetail.class, value);
                        addComponent(VehicleComponent.class, DaggerVehicleComponent.builder()
                                .sectionComponent(getComponent(SectionComponent.class))
                                .vehicleModule(new VehicleModule(value))
                                .build());
                        mCurrentVehicleNumber = vehicleNumber;
                        vehicleInformationDetail = value;
                        mVehicleNumberModel.setHint(mCurrentVehicleNumber);

                        CheckInRecordActivity fragment = new CheckInRecordActivity();
//                        fragment.setOnCheckInOperationFinishedListener(new CheckInOperationFragment.OnCheckInOperationFinishedListener() {
//                            @Override
//                            public void onCheckInOperationFinished() {
//                                mVehicleNumberModel.setValue(null);
//                                mVehicleNumberModel.setHint(null);
//                                mCurrentVehicleNumber = null;
//                                loadEmptyFragment();
//                            }
//                        });
                        loadFragment(fragment);
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        new AlertDialog.Builder(CheckInActivity.this)
                                .setTitle("错误")
                                .setMessage("查询车架号:" + vehicleNumber + "失败！")
                                .setCancelable(false)
                                .setNegativeButton("清空数据", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        mVehicleNumberModel.setValue(null);
                                        mVehicleNumberModel.setHint(null);
                                        mCurrentVehicleNumber = null;
                                    }
                                })
                                .create()
                                .show();
                    }

                    @Override
                    public void onComplete() {
                        mVehicleNumberModel.setEntries(null);
                    }
                });
            }
        };

//        if (!TextUtils.isEmpty(mCurrentVehicleNumber)) {
//            new AlertDialog.Builder(this)
//                    .setMessage("点检记录未上传，请上传记录后再重新录入车架号")
//                    .setPositiveButton("好", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            mVehicleNumberModel.setValue(null);
//                        }
//                    })
//                    .setNegativeButton("不保存记录，重新录入", new DialogInterface.OnClickListener() {
//
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            showRunnable.run();
//                        }
//                    })
//                    .create()
//                    .show();
//        } else {
        showRunnable.run();
//        }
    }

    private void loadEmptyFragment() {
        EmptyContentFragment fragment = new EmptyContentFragment();
        fragment.setEmptyText("没有数据，请先输入车架号");
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commitAllowingStateLoss();
    }

    private void loadProcessingFragment() {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, new ProcessingFragment());
        fragmentTransaction.commitAllowingStateLoss();
    }

    private void loadFragment(Fragment f) {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                .beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, f);
        fragmentTransaction.commitAllowingStateLoss();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == QR_REQUEST) {
            if (resultCode == RESULT_OK) {
                final String code = data.getStringExtra("code");
                Toast.makeText(this, "QRcode = " + code, Toast.LENGTH_SHORT).show();
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        loadDetail(code);
                        mVehicleNumberModel.setValue(code);
                    }
                });
                return;
            } else {
                Toast.makeText(this, "qr scan failed", Toast.LENGTH_SHORT).show();
            }
        } else if (requestCode == CONF_REQUEST) {
            SectionComponent component = getComponent(SectionComponent.class);
            if (component == null) {
                new AlertDialog.Builder(this)
                        .setTitle("错误")
                        .setMessage("请先选择点检环节")
                        .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                initConfiguration();
                            }
                        })
                        .create()
                        .show();
            } else {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        initData();
                    }
                });
                component.inject(this);
            }
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    private Observable.OnPropertyChangedCallback mOnVehicleNumberChangedListener = new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable sender, int propertyId) {
            if (propertyId == BR.value) {
                mHandler.removeCallbacks(mGetAutoCompleteDateRunnable);
                mHandler.postDelayed(mGetAutoCompleteDateRunnable, 300);
            }
        }
    };

    private Runnable mGetAutoCompleteDateRunnable = new Runnable() {
        @Override
        public void run() {
            MyLog.d(TAG, "run:mGetAutoCompleteDateRunnable");

            if (mVehicleNumberModel.getValue() == null
                    || mVehicleNumberModel.getValue().length() <= 3
                    || mVehicleNumberModel.getValue().equals(mCurrentVehicleNumber))
                return;

            if (mPendingDisposable != null && !mPendingDisposable.isDisposed()) {
                mPendingDisposable.dispose();
            }

            mPendingDisposable = new DisposableObserver<List<Pair<String, String>>>() {
                @Override
                protected void onStart() {
                    super.onStart();
                    mVehicleNumberModel.setEntries(Arrays.asList(new Pair<String, String>("<查询中......>", null)));
                }

                @Override
                public void onNext(List<Pair<String, String>> value) {
                    MyLog.d(TAG, "onNext: mGetAutoCompleteDateRunnable");
                    mVehicleNumberModel.setEntries(value);
                    if (value.size() == 1) {
                        // 只有一个结果自动填充并开始做下一步查询
                        loadDetail(value.get(0).first);
                    } else if (value.size() == 0) {
                        mVehicleNumberModel.setEntries(Arrays.asList(new Pair<String, String>("<找不到车架号>", null)));
                    }
                }

                @Override
                public void onError(Throwable e) {
                    e.printStackTrace();
                    mVehicleNumberModel.setEntries(Arrays.asList(new Pair<String, String>("<查询失败>", null)));
                }

                @Override
                public void onComplete() {

                }
            };
            mapUtil.mapInformationItemAutoCompleteTextModel(
                    mVehicleNumberModel.getValue(),
                    mBrand.getBrand_code(), ""
                    , mPendingDisposable);
        }
    };

    View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(CheckInActivity.this, QRScannerActivity.class));

//            // testcode
//            intent.putExtra("format", BarcodeFormat.CODE_39.name());
//            intent.putExtra("regular", "^[0-9]*-[0-9]*$");
            intent.putExtra("regular", "");

            startActivityForResult(intent, QR_REQUEST);
        }
    };

    BroadcastReceiver mTimeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
                mTimeModel.setValue(Util.getCurrentTime(CheckInActivity.this));
            }
        }
    };

    AdapterView.OnItemClickListener mOnVehicleNumberClick = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // start get detail info
            MyLog.d(TAG, "onItemClick: ");
            mHandler.removeCallbacks(mGetAutoCompleteDateRunnable);

            //check
            try {
                if (mVehicleNumberModel.getValue() == null
                        || !mVehicleNumberModel.getValue().equals(
                        mVehicleNumberModel.getEntries().get(position).first)
                        || (mVehicleNumberModel.getValue().startsWith("<") && mVehicleNumberModel.getValue().endsWith(">"))) {
                    MyLog.e(TAG, "onItemClick: check data consistency failed");
                    return;
                }
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

            loadDetail(mVehicleNumberModel.getValue());
        }
    };

    void onMassLossBtnClick(View view) {
        if (!TextUtils.isEmpty(mCurrentVehicleNumber))
            SelectCheckPointActivity.actionStart(this, vehicleInformationDetail.getVoyage(), vehicleInformationDetail.getType(), "", "");
    }

    void onRandomInspectionClick(View view) {
        if (!TextUtils.isEmpty(mCurrentVehicleNumber)) {
            Intent intent = new Intent(getApplicationContext(), RandomInspectionActivty.class);
            intent.putExtra("vin", mCurrentVehicleNumber);
            intent.putExtra("brand_code", mBrand.getBrand_code());
            intent.putExtra("brand_name", mBrand.getBrand_name());
            startActivity(intent);
        }
    }

    void onNamePalteBtnClick(View view) {
        if (!TextUtils.isEmpty(mCurrentVehicleNumber)) {
            Intent intent = new Intent(getApplicationContext(), NamePlateActivity.class);
            intent.putExtra("vin", mCurrentVehicleNumber);
            intent.putExtra("brand_code", mBrand.getBrand_code());
            intent.putExtra("brand_name", mBrand.getBrand_name());
            startActivity(intent);
        }
    }

    void onRecordBtnClick(View view) {
        if (!TextUtils.isEmpty(mCurrentVehicleNumber)) {
            Intent intent = new Intent(getApplicationContext(), CheckInRecordActivity.class);
//            intent.putExtra("vin", mCurrentVehicleNumber);
            startActivity(intent);
        }
    }

    void onWorkloadBtnClick(View view) {
        Intent intent = new Intent(getApplicationContext(), CheckInWorkLoadActivity.class);
        intent.putExtra("brandname", mBrand.getBrand_name());
        intent.putExtra("brandcode", mBrand.getBrand_code());
        intent.putExtra("nodecode", mInspectionSection.getNode_code());
        intent.putExtra("nodename", mInspectionSection.getNode_name());
        startActivity(intent);
    }

    void showRemark(String remark) {
        Toast toast = new Toast(this);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView textView = new TextView(this);
        textView.setTextSize(getResources().getDimension(R.dimen.center_toast_size));
        textView.setText(remark);
        textView.setBackgroundColor(0xFF000000);
        textView.setTextColor(0xFFFFFFFF);
        toast.setView(textView);
        toast.show();
    }

    @Override
    protected void onResume() {
        super.onResume();


    }
}

